package com.ruoyi.web.controller.cj;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ShopNotice;
import com.ruoyi.system.service.IShopNoticeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公告Controller
 * 
 * @author ruoyi
 * @date 2020-10-24
 */
@Controller
@RequestMapping("/system/shopNotice")
public class ShopNoticeController extends BaseController
{
    private String prefix = "system/shopNotice";

    @Autowired
    private IShopNoticeService shopNoticeService;

    @RequiresPermissions("system:shopNotice:view")
    @GetMapping()
    public String shopNotice()
    {
        return prefix + "/shopNotice";
    }

    /**
     * 查询公告列表
     */
    @RequiresPermissions("system:shopNotice:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ShopNotice shopNotice)
    {
        startPage();
        List<ShopNotice> list = shopNoticeService.selectShopNoticeList(shopNotice);
        return getDataTable(list);
    }

    /**
     * 导出公告列表
     */
    @RequiresPermissions("system:shopNotice:export")
    @Log(title = "公告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ShopNotice shopNotice)
    {
        List<ShopNotice> list = shopNoticeService.selectShopNoticeList(shopNotice);
        ExcelUtil<ShopNotice> util = new ExcelUtil<ShopNotice>(ShopNotice.class);
        return util.exportExcel(list, "shopNotice");
    }

    /**
     * 新增公告
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存公告
     */
    @RequiresPermissions("system:shopNotice:add")
    @Log(title = "公告", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ShopNotice shopNotice)
    {
        return toAjax(shopNoticeService.insertShopNotice(shopNotice));
    }

    /**
     * 修改公告
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ShopNotice shopNotice = shopNoticeService.selectShopNoticeById(id);
        mmap.put("shopNotice", shopNotice);
        return prefix + "/edit";
    }

    /**
     * 修改保存公告
     */
    @RequiresPermissions("system:shopNotice:edit")
    @Log(title = "公告", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ShopNotice shopNotice)
    {
        return toAjax(shopNoticeService.updateShopNotice(shopNotice));
    }

    /**
     * 删除公告
     */
    @RequiresPermissions("system:shopNotice:remove")
    @Log(title = "公告", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(shopNoticeService.deleteShopNoticeByIds(ids));
    }
}
